<?php
/**
 * 说明：医院页面控制器
 * 默认index方法负责判断并转发分站
 */
class Hospital extends Controller {

	function Hospital()
	{
		parent::Controller();
		$this->load->helper('cookie');
		$this->load->library('myfunction');   //载入自定义函数库
		$this->load->model('access_model');  //载入访客接入判断模型
		$this->load->model('user_model');  //载入用户模型
		$this->load->model('article_model');  //载入文章模型
		$this->load->model('hospital_model');  //载入医院模型
	}

	function index() {
		$this->access_model->judgearea();//判断访客地区（已写入session和cookie信息）
		$data['baseurl']=base_url();
		$data['area']=$_SESSION['siteinfo']['area'];
		$data['areacode']=$_SESSION['siteinfo']['areacode'];
		$data['site']=$_SESSION['siteinfo']['site'];
		$hs_id=$this->uri->segment(3);
		if(!ereg("^[a-zA-Z]{2}[0-9]+$",$hs_id)) {  //如果HSID非法(前两位为字母，结尾为数字)，直接转向404
			show_404('nothing');
		}else{
			$data['hospital']=$this->hospital_model->get_onehospital_info($hs_id);//读取医院信息
			if(empty($data['hospital'])) {  //如果检索出医院信息
				show_404('nothing');
			}else{
				$data['head_info']="<link href=\"css/hospital.css\" type=\"text/css\" rel=\"stylesheet\"><script defer type=\"Text/Javascript\" src=\"js/faces.js\"></script>";//网页head区域信息
				$data['web_title']=$data['hospital']['name'].'——好医生导医网';//浏览器标题
				$this->load->view('topbar_view',$data);
				$data['hospital']['baseintro']=$this->myfunction->trimmed_title($data['hospital']['intro'],100);//截取长字符串
				$rankid=$data['hospital']['rank'];
				$data['hospital']['rank']=$this->hospital_model->get_hsrank_info($rankid);
				$hs_article=$this->article_model->get_hos_article($data['hospital']['hs_id'],1);//读取相关新闻题目列表
				$data['hs_article']=$hs_article;
				$i=0;
				foreach ($data['hs_article'] as $h){
					$data['hs_article'][$i]['tit']=$this->myfunction->trimmed_title($h['title'],15);//截取长字符串
					$i++;
				}
				//获取医院下属科室信息
				$data['dept_list']=$this->hospital_model->get_dept_list($data['hospital']['hs_id']);
				if (!empty($data['dept_list'])){
					$i=0;
					foreach ($data['dept_list'] as $dt){//单独将科室类别写入dts数组供循环输出
						$dts[$i]=$dt['depttype'];
						$i++;
					}
					$data['dts']=array_unique($dts);//取消掉科室类别数组重复值
				}
				$this->load->view('hospital_view',$data);
			}
		}

	}

	//合作医院列表（根据行政区域分类）
	function native() {
		$native_id=intval($this->uri->segment(3,0));//限制整型,如果没有URI参数，则默认$native_id=0
		if ((!isset($_SESSION['siteinfo'])) || (count($_SESSION['siteinfo'])!=3)) {	//如果session里没有写入siteinfo信息
			$this->access_model->judgearea(); //判断访客地区（已写入session和cookie信息）
		}
		$data['baseurl']=base_url();
		$data['area']=$_SESSION['siteinfo']['area'];
		$data['areacode']=$_SESSION['siteinfo']['areacode'];
		$data['site']=$_SESSION['siteinfo']['site'];
		$data['head_info']="<link href=\"css/common.css\" type=\"text/css\" rel=\"stylesheet\"><link href=\"css/hoslist.css\" type=\"text/css\" rel=\"stylesheet\">";//网页head区域信息
		$data['web_title']="好医生导医网——".$data['area']."站";//浏览器标题
		$this->load->view('topbar_view',$data);
		$this->load->view('head_view',$data);
		//读取该城市行政区域信息
		$nativearea = $this->hospital_model->get_nativearea_list($data['areacode']);
		//输出主菜单内容
		$data['bignav']='<li class="first"><a target="_self" href="/"><span>首页</span></a></li>';
		$data['bignav']=$data['bignav'].'<li class="current"><a target="_self" href="hospital/native"><span>合作医院</span></a></li>';
		$data['bignav']=$data['bignav'].'<li class="current-next"><a target="_self" href="hospital/depttype"><span>推荐专科</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="#"><span>疾病指南</span></a></li>';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="exam"><span>优惠体检</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="#"><span>大河名医馆</span></a></li>';
		//输出副菜单内容
		$data['smallnav']='<li class="first"><a target="_self" href="#"><span>服务预约</span></a></li>';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="#"><span>在线购卡</span></a></li>	';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="service"><span>客服中心</span></a></li>	';
		//输出mini菜单
		if(!empty($nativearea)) {
			$data['mininav']='<li class="first"><a href="#" style="color:#555;text-decoration:none;cursor:default;"><span>按区域查找：</span></a></li>';
			foreach ($nativearea as $na){
				$data['mininav']=$data['mininav'].'<li><a target="_self" href="hospital/native/'.$na['Id'].'"><span>'.$na['nativename'].'</span></a></li>';
			}
		}
		$this->load->view('nav_view',$data);
		//----------------------------------------------------------------------------------------------------------//
		$page_num = '5';//每页的数据
		$total_nums=$this->hospital_model->get_hospital_num($data['areacode'],$native_id);//读取该分站总医院数量
		$data['hospital_list']=$this->hospital_model->get_hospital_list($data['areacode'],$native_id,$page_num,$this->uri->segment(4));//读出医院列表
		if (!empty($data['hospital_list'])) {//如果查询到了结果
			$c=count($data['hospital_list'])-1;
				for($i=0;$i<=$c;$i++) {
					//$data['hospital_list'][$i]['brief']=$this->myfunction->trimmed_title($data['hospital_list'][$i]['brief'],60);//截取长字符串
					$data['hospital_list'][$i]['intro']=$this->myfunction->trimmed_title($data['hospital_list'][$i]['intro'],60);//截取长字符串
					$data['hospital_list'][$i]['vip']=$this->myfunction->trimmed_title($data['hospital_list'][$i]['vip'],40);//截取长字符串
				}
		}
		$data['num']=$total_nums;
		if($native_id==0) {
			$data['listinfo']="<span>".$data['area']."</span> 共有 <span>".$data['num']."</span> 家合作医院";
		}else{
			$native_name=$this->hospital_model->get_nativearea_name($native_id);//获取行政区域名称
			$data['listinfo']="<span>".$data['area'].$native_name['nativename']."</span> 共有 <span>".$data['num']."</span> 家合作医院";
		}
		$this->load->library('pagination');
		$config['base_url'] = base_url().'hospital/native/'.$native_id;
		$config['uri_segment'] = 4;
		$config['total_rows'] = $total_nums;//总共多少条数据
		$config['per_page'] = $page_num;//每页显示几条数据
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
		$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
		$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
		$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
		$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
		$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
		$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
		$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
		$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
		$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
		$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
		$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
		$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
		$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
		$config['num_tag_close'] = '</li>';
		$this->pagination->initialize($config);
		$data['article_yyzx_list'] = $this->article_model->output_article_list($data['areacode'],2,0,20); //输出文章列表（分类1：0，条数2）
			if (!empty($data['article_yyzx_list'])) {//如果查询到了结果
				$c=count($data['article_yyzx_list'])-1;
					for($i=0;$i<=$c;$i++) {
						$data['article_yyzx_list'][$i]['tit']=$this->myfunction->trimmed_title($data['article_yyzx_list'][$i]['title'],12);//截取长字符串
					}
			}
		$this->load->view('hoslist_view',$data);
		$this->load->view('link_view',$data);
		//-----------------------------------------------foot_view--------------------------------------------------//
		$this->load->view('foot_view',$data);
	}

	//科室列表
	function depttype() {
		$type_id=intval($this->uri->segment(3,0));//限制整型,如果没有URI参数，则默认$type_id=0
		if ((!isset($_SESSION['siteinfo'])) || (count($_SESSION['siteinfo'])!=3)) {	//如果session里没有写入siteinfo信息
			$this->access_model->judgearea(); //判断访客地区（已写入session和cookie信息）
		}
		$data['baseurl']=base_url();
		$data['area']=$_SESSION['siteinfo']['area'];
		$data['areacode']=$_SESSION['siteinfo']['areacode'];
		$data['site']=$_SESSION['siteinfo']['site'];
		$data['head_info']="<link href=\"css/common.css\" type=\"text/css\" rel=\"stylesheet\"><link href=\"css/hoslist.css\" type=\"text/css\" rel=\"stylesheet\">";//网页head区域信息
		$data['web_title']="好医生导医网——".$data['area']."站";//浏览器标题
		$this->load->view('topbar_view',$data);
		$this->load->view('head_view',$data);
		//读取科室类别信息
		$depttype = $this->hospital_model->get_depttype_info();
		//输出主菜单内容
		$data['bignav']='<li class="first"><a target="_self" href="/"><span>首页</span></a></li>';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="hospital/native"><span>合作医院</span></a></li>';
		$data['bignav']=$data['bignav'].'<li class="current"><a target="_self" href="hospital/depttype"><span>推荐专科</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li class="current-next"><a target="_self" href="#"><span>疾病指南</span></a></li>';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="exam"><span>优惠体检</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="#"><span>大河名医馆</span></a></li>';
		//输出副菜单内容
		$data['smallnav']='<li class="first"><a target="_self" href="#"><span>服务预约</span></a></li>';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="#"><span>在线购卡</span></a></li>	';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="service"><span>客服中心</span></a></li>	';
		//输出mini菜单
		if(!empty($depttype)) {
			$data['mininav']='<li class="first"><a href="#" style="color:#555;text-decoration:none;cursor:default;"><span>按类别查找：</span></a></li>';
			foreach ($depttype as $dt){
				$data['mininav']=$data['mininav'].'<li><a target="_self" href="hospital/depttype/'.$dt['Id'].'"><span>'.$dt['typename'].'</span></a></li>';
			}
		}
		$this->load->view('nav_view',$data);
		//----------------------------------------------------------------------------------------------------------//
		$page_num = '20';//每页的数据
		$total_nums=$this->hospital_model->get_dept_num(null,$data['areacode'],$type_id);//读取科室数量
		$data['dept_list']=$this->hospital_model->get_dept_list(0,$data['areacode'],$page_num,intval($this->uri->segment(4)),$type_id);//读出科室列表
		if (!empty($data['dept_list'])) {//如果查询到了结果
			$c=count($data['dept_list'])-1;
				for($i=0;$i<=$c;$i++) {
					$data['dept_list'][$i]['hs']=$this->hospital_model->get_onehospital_name($data['dept_list'][$i]['hs_id']);//查询出所属医院
					$data['dept_list'][$i]['sintro']=$this->myfunction->trimmed_title($data['dept_list'][$i]['intro'],50);//截取长字符串
				}
		}
		$data['num']=$total_nums;
		if($type_id==0) {
			$data['listinfo']="<span>".$data['area']."</span> 共有 <span>".$data['num']."</span> 个推荐专科";
		}else{
			$type_name=$this->hospital_model->get_depttype_info($type_id);//获取科室类别名称
			$data['listinfo']="<span>".$type_name."</span> 共有 <span>".$data['num']."</span> 个推荐专科";
		}
		$this->load->library('pagination');
		$config['base_url'] = base_url().'hospital/depttype/'.$type_id;
		$config['uri_segment'] = 4;
		$config['total_rows'] = $total_nums;//总共多少条数据
		$config['per_page'] = $page_num;//每页显示几条数据
		$config['first_link'] = '首页';
		$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
		$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
		$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
		$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
		$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
		$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
		$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
		$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
		$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
		$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
		$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
		$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
		$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
		$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
		$config['num_tag_close'] = '</li>';
		$this->pagination->initialize($config);
		$this->load->view('deptlist_view',$data);
		$this->load->view('link_view',$data);
		//-----------------------------------------------foot_view--------------------------------------------------//
		$this->load->view('foot_view',$data);
	}

}
?>
